package scuts.core.lifting;


import scuts.core.types.Either;

class LiftWithEither1 
{

  public static function liftWithEitherRight <A, B, L> (f:A->B):Either<L, A>->Either<L, B> 
  {
    return function (a:Either<L, A>) {
      return switch (a) {
        case Left(l): Left(l);
        case Right(r):    Right(f(r));
      }
    }
  }
  
  public static function liftWithEitherLeft <A, B, R> (f:A->B):Either<A, R>->Either<B, R> 
  {
    return function (a:Either<A, R>) {
      return switch (a) {
        case Left(l): Left(f(l));
        case Right(r): Right(r);
      }
    }
  }
}

class LiftWithEither2 
{
  // passes the most left Left Value to the result
  public static function liftWithEitherRight <A, B, C, L> (f:A->B->C):Either<L, A>->Either<L, B>->Either<L, C> 
  {
    return function (a:Either<L, A>, b:Either<L, B>) {
      return switch (a) {
        case Left(l1): Left(l1);
        case Right(r1): 
          switch(b) {
            case Left(l2): Left(l2);
            case Right(r2): Right(f(r1, r2));
          }
      }
    }
  }

}